/**
 *
 * @author 
 *
 */
class MyLibrary {
    public static stageW = 480;
    public static stageH = 800;
    public static stageScale = 2;//放大比例
    public static txtContent_Size = 25 * 2;

    public constructor() {
    }
    
    static init(w:number,h:number){
        this.stageW = w;
        this.stageH = h;
        this.stageScale = w / 600;
    }
	
    //影片对象
    static createMovieClipByName(namse: string,anX_Y: Boolean = false,scale:number=1): egret.MovieClip {
        var spr1: egret.MovieClip = new egret.MovieClip();
        var data = RES.getRes(namse + "_json");
        var texture = RES.getRes(namse + "_png");
        var mcDataFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(data,texture);
        spr1 = new egret.MovieClip(mcDataFactory.generateMovieClipData(namse));
        if(anX_Y) {
            spr1.anchorOffsetX = spr1.width / 2;
            spr1.anchorOffsetY = spr1.height / 2;
        } 
        //if(scale > 1) {
           // spr1.scaleX = scale;
           // spr1.scaleY = scale;
           // spr1.cacheAsBitmap = true;
       // }
        return spr1;
    }
    /**
    * 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
    * Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
    */
    static createBitmapByName(name: string,anX_Y:Boolean = false,w:number = 0,h:number = 0): egret.Bitmap {
        var result: egret.Bitmap = new egret.Bitmap();
        var texture: egret.Texture = RES.getRes(name);
        result.texture = texture;
        if(anX_Y){
            result.anchorOffsetX =result.width / 2;
            result.anchorOffsetY = result.height / 2;
        }        
        if(w > 0){
            result.width = w;
        }
        if(h > 0){
            result.height = h;
        }
        return result;
    }
    static updateStage(W: number,H: number) {
        this.stageW = W;
        this.stageH = H;
    }
    
    static createTextByName(str: string,anX_Y:Boolean = false,Color:number = 0xFFFFFF,Size: number = 30,mode: string ="center",ls:number=20,Bold:Boolean=false):egret.TextField{
         var tex: egret.TextField = new egret.TextField();
         tex.fontFamily = "黑体";
         tex.text = str;//`没有人意识到\n通的意义，并非是沟通本身\n包括我们`;
         tex.size = Size;
         tex.textColor = Color;
         if(Bold == true){
            tex.bold = true;
         }else{
            tex.bold = false;
         }
         
         tex.wordWrap = true;
         tex.lineSpacing = ls;
         tex.textAlign = mode;
         if(anX_Y) {
             tex.anchorOffsetX = tex.width / 2;
             tex.anchorOffsetY = tex.height / 2;
         } 
         return tex;
     }
}
